package com.itcat.controller;

import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.UmsResourceCategory;
import com.itcat.service.UmsResourceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * [一句话描述该类的功能]
 *
 * @author : [Cr Mr]
 * @version : [v1.0]
 * @date : [2022/4/3 20:15]
 */
@RestController
@RequestMapping("resourceCategory")
public class UmsResourceCategoryController {

    @Autowired
    private UmsResourceCategoryService umsResourceCategoryService;

    /***
     * 查询所有后台资源分类
     * @author Cr Mr
     * @date 2022/4/3 20:20
     */
    @GetMapping("listAll")
    public CommonResult listAll() {
        List<UmsResourceCategory> list = umsResourceCategoryService.listAll();
        return CommonResult.success(list);
    }

    /***
     * 添加后台资源分类
     * @author Cr Mr
     * @date 2022/4/4 10:30
     */
    @PostMapping("create")
    public CommonResult create(@RequestBody UmsResourceCategory umsResourceCategory) {
        umsResourceCategoryService.create(umsResourceCategory);
        return CommonResult.success();
    }

    /***
     * 根据ID删除后台资源
     * @author Cr Mr
     * @date 2022/4/4 10:30
     */
    @PostMapping("delete/{id}")
    public CommonResult delete(@PathVariable Long id) {
        umsResourceCategoryService.delete(id);
        return CommonResult.success();
    }

    /***
     * 修改后台资源分类
     * @author Cr Mr
     * @date 2022/4/4 10:30
     */
    @PostMapping("update/{id}")
    public CommonResult update(@PathVariable Long id, @RequestBody UmsResourceCategory umsResourceCategory) {
        umsResourceCategoryService.update(id, umsResourceCategory);
        return CommonResult.success();
    }
}
